import '../helper/dioHelper2.dart';

class SpaceItem {
  int ID;
  String Guid;
  String UserId;
  String SpaceId;
  int FType;
  String FileName;
  String CreateTime;
  int State;
  int Size;
  String Title;
  String Description;
  String Remarks;
  String Gps;
  String Location;
  String TagName;

  SpaceItem(
      this.ID,
      this.Guid,
      this.UserId,
      this.SpaceId,
      this.FType,
      this.FileName,
      this.CreateTime,
      this.State,
      this.Size,
      this.Title,
      this.Description,
      this.Remarks,
      this.Gps,
      this.Location,
      this.TagName);
  SpaceItem.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        UserId = json["UserId"],
        SpaceId = json["SpaceId"],
        FType = json["FType"],
        FileName = json["FileName"],
        CreateTime = json["CreateTime"],
        State = json["State"],
        Size = json["Size"],
        Title = json["Title"],
        Description = json["Description"],
        Remarks = json["Remarks"],
        Gps = json["Gps"],
        Location = json["Location"],
        TagName = json["TagName"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'UserId': UserId,
        'SpaceId': SpaceId,
        'FType': FType,
        'FileName': FileName,
        'CreateTime': CreateTime,
        'State': State,
        'Size': Size,
        'Title': Title,
        'Description': Description,
        'Remarks': Remarks,
        'Gps': Gps,
        'Location': Location,
        'TagName': TagName,
      };

  static Future<bool> Add(SpaceItem x1) async {
    var response = await DioHelper.Post("/SpaceItem/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(SpaceItem x1) async {
    var response = await DioHelper.Post("/SpaceItem/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(SpaceItem x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/SpaceItem/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<SpaceItem?> Get(String guid) async {
    var response = await DioHelper.Get("/SpaceItem/Get?id=$guid", {});

    if (response.statusCode == 200)
      return new SpaceItem.fromJson(response.data);
    return null;
  }

  static Future<List<SpaceItem>> GetList(
      String id, int fType, int pageIndex, int pageSize) async {
    String p1 = pageIndex.toString();
    String ps = pageSize.toString();

    var response = await DioHelper.Get(
        "/SpaceItem/GetList?SpaceId=$id&fType=$fType&p1=$p1&ps=$ps", {});

    var list1 = <SpaceItem>[];
    if (response.statusCode == 200) {
      if (response.data == null) return list1;
      for (var x in response.data) {
        list1.add(new SpaceItem.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<SpaceItem>> GetList2(
      String id, int pageIndex, int pageSize) async {
    String p1 = pageIndex.toString();
    String ps = pageSize.toString();

    var response = await DioHelper.Get(
        "/SpaceItem/GetList2?SpaceId=$id&p1=$p1&ps=$ps", {});

    var list1 = <SpaceItem>[];
    if (response.statusCode == 200) {
      if (response.data == null) return list1;
      for (var x in response.data) {
        list1.add(new SpaceItem.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<SpaceItem>> GetAllList() async {
    var response = await DioHelper.Get("/SpaceItem/GetAllList", {});
    var list1 = <SpaceItem>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new SpaceItem.fromJson(x));
      }
    }
    return list1;
  }
}
